home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / scribus-ng / scripts / CalendarWizard.py next >
Encoding:
Python Source  |  2009-12-05  |  21.3 KB  |  543 lines

  1. # -*- coding: utf-8 -*-
  2.  
  3. """ This is a simple 'Calendar creation wizard' for Scribus. It's a fully
  4. rewritten Calender.py from Scribus examples. Enjoy.
  5.  
  6. DESCRIPTION & USAGE:
  7. This script needs Tkinter. It will create a GUI with available options
  8. for easy calendar page creation. You'll get new pages with calendar
  9. tables into a new document you are asked for. Position of the
  10. objects in page is calculated with the "golden-ratio" aspect from the
  11. page margins.
  12.  
  13. Steps to create:
  14.     1) Fill requested values in the Calendar dialog
  15.     2) You will be prompted for new document
  16.     3) You will be prompted for new paragraph style which will be used
  17.        in calendar text frames. It could be changed later.
  18.  
  19. There are 2 types of calender supported:
  20.     1) Classic calendar with one month matrix per page. I suggest
  21.        here PORTRAIT orientation.
  22.     2) Event calendar with one week per page with huge place for
  23.        human inputs. There should be LANDSCAPE imho.
  24.  
  25. But everything works with both orientations well of course too.
  26.  
  27. AUTHOR:
  28.     Petr Vanek <petr@scribus.info>
  29.  
  30. LICENSE:
  31. This program is free software; you can redistribute it and/or modify
  32. it under the terms of the GNU General Public License as published by
  33. the Free Software Foundation; either version 2 of the License, or
  34. (at your option) any later version.
  35.  
  36. This program is distributed in the hope that it will be useful,
  37. but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. GNU General Public License for more details.
  40.  
  41. You should have received a copy of the GNU General Public License
  42. along with this program; if not, write to the Free Software
  43. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  44.  
  45. """
  46.  
  47. import sys
  48. import calendar
  49. import datetime
  50.  
  51. try:
  52.     from scribus import *
  53. except ImportError:
  54.     print "This Python script is written for the Scribus scripting interface."
  55.     print "It can only be run from within Scribus."
  56.     sys.exit(1)
  57.  
  58. try:
  59.     # I wish PyQt installed everywhere :-/
  60.     from Tkinter import *
  61.     from tkFont import Font
  62. except ImportError:
  63.     print "This script requires Python's Tkinter properly installed."
  64.     messageBox('Script failed',
  65.                'This script requires Python\'s Tkinter properly installed.',
  66.                ICON_CRITICAL)
  67.     sys.exit(1)
  68.  
  69.  
  70. localization = {
  71. 'Catalan' :
  72.     [['Gener', 'Febrer', 'Mar├º', 'Abril', 'Maig',
  73.       'Juny', 'Juliol', 'Agost', 'Setembre',
  74.       'Octubre', 'Novembre', 'Desembre'],
  75.      ['Dilluns', 'Dimarts', 'Dimecres', 'Dijous', 'Divendres', 'Dissabte', 'Diumenge']],
  76. 'Catalan-short' :
  77.     [['Gener', 'Febrer', 'Mar├º', 'Abril', 'Maig',
  78.       'Juny', 'Juliol', 'Agost', 'Setembre',
  79.       'Octubre', 'Novembre', 'Desembre'],
  80.      ['Dl', 'Dm', 'Dc', 'Dj', 'Dv', 'Ds', 'Dg']],
  81. # Catalan by "Cesc Morata" <atarom@gmail.com>
  82. 'Czech' :
  83.     [['Leden', '├Ünor', 'B┼Öezen', 'Duben', 'Kv─¢ten',
  84.         '─îerven', '─îervenec', 'Srpen', 'Z├í┼Ö├¡',
  85.         '┼ÿ├¡jen', 'Listopad', 'Prosinec'],
  86.      ['Pond─¢l├¡','├Üter├╜','St┼Öeda','─îtvrtek','P├ítek','Sobota', 'Ned─¢le']],
  87. 'Czech-short' :
  88.     [['Leden', '├Ünor', 'B┼Öezen', 'Duben', 'Kv─¢ten',
  89.         '─îerven', '─îervenec', 'Srpen', 'Z├í┼Ö├¡',
  90.         '┼ÿ├¡jen', 'Listopad', 'Prosinec'],
  91.      ['Po', '├Üt', 'St', '─ît', 'P├í', 'So', 'Ne']],
  92. 'Dutch' :
  93.     [['Januari', 'Februari', 'Maart', 'April',
  94.       'Mei', 'Juni', 'Juli', 'Augustus', 'September',
  95.       'Oktober', 'November', 'December'],
  96.      ['Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag', 'Zondag']],
  97. # Dutch by "Christoph Sch├ñfer" <christoph-schaefer@gmx.de>
  98. 'English' :
  99.     [['January', 'February', 'March', 'April',
  100.       'May', 'June', 'July', 'August', 'September',
  101.       'October', 'November', 'December'],
  102.      ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday', 'Sunday']],
  103. 'English-short' :
  104.     [['January', 'February', 'March', 'April', 'May',
  105.       'June', 'July', 'August', 'September', 'October',
  106.       'November', 'December'],
  107.      ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']],
  108. 'Finnish' :
  109.     [['Tammikuu', 'Helmikuu', 'Maaliskuu', 'Huhtikuu',
  110.       'Toukokuu', 'Kes├ñkuu', 'Hein├ñkuu', 'Elokuu', 'Syyskuu',
  111.       'Lokakuu', 'Marraskuu', 'Joulukuu'],
  112.      ['ma','ti','ke','to','pe','la', 'su']],
  113. 'French':
  114.     [['Janvier', u'F\xe9vrier', 'Mars', 'Avril',
  115.       'Mai', 'Juin', 'Juillet', u'Ao\xfbt', 'Septembre',
  116.       'Octobre', 'Novembre', u'D\xe9cembre'],
  117.      ['Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi','Dimanche']],
  118. 'German' :
  119.     [['Januar', 'Februar', u'M\xe4rz', 'April',
  120.       'Mai', 'Juni', 'Juli', 'August', 'September',
  121.       'Oktober', 'November', 'Dezember'],
  122.      ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag']],
  123. 'Italian' :
  124.     [['Gennaio', 'Febbraio', 'Marzo', 'Aprile',
  125.        'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre',
  126.        'Ottobre', 'Novembre', 'Dicembre'],
  127.     [u'Luned\xec', u'Marted\xec', u'Mercoled\xec', u'Gioved\xec', u'Venerd\xec', 'Sabato', 'Domenica']],
  128. # Polish by "┼üukasz [DeeJay1] Jerna┼¢" <deejay1@nsj.srem.pl>
  129. 'Polish' :
  130.     [['Stycze┼ä', 'Luty', 'Marzec', 'Kwiecie┼ä', 'Maj',
  131.       'Czerwiec', 'Lipiec', 'Sierpie┼ä', 'Wrzesie┼ä',
  132.       'Pa┼║dziernik', 'Listopad', 'Grudzie┼ä'],
  133.      ['Poniedzia┼éek', 'Wtorek', '┼Üroda', 'Czwartek', 'Pi─àtek', 'Sobota', 'Niedziela']],
  134. 'Portuguese' :
  135.     [['Janeiro', 'Fevereiro', u'Mar\xe7o', 'Abril',
  136.       'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro',
  137.       'Outubro', 'Novembro', 'Dezembro'],
  138.      ['Segunda-feira', u'Ter\xe7a-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', u'S\xe1bado', 'Domingo']],
  139. # Romanian by Costin Stroie <costinstroie@eridu.eu.org>
  140. 'Romanian' :
  141.     [['Ianuarie', 'Februarie', 'Martie', 'Aprilie',
  142.       'Mai', 'Iunie', 'Iulie', 'August', 'Septembrie',
  143.       'Octombrie', 'Noiembrie', 'Decembrie'],
  144.      ['Luni','Mar\xc8\x9bi','Miercuri','Joi','Vineri','S\xc3\xa2mb\xc4\x83t\xc4\x83', 'Duminic\xc4\x83']],
  145. 'Russian' :
  146.     [['╨»╨╜╨▓╨░╤Ç╤î', '╨ñ╨╡╨▓╤Ç╨░╨╗╤î', '╨£╨░╤Ç╤é', '╨É╨┐╤Ç╨╡╨╗╤î',
  147.       '╨£╨░╨╣', '╨ÿ╤Ä╨╜╤î', '╨ÿ╤Ä╨╗╤î', '╨É╨▓╨│╤â╤ü╤é', '╨í╨╡╨╜╤é╤Å╨▒╤Ç╤î',
  148.       '╨₧╨║╤é╤Å╨▒╤Ç╤î', '╨¥╨╛╤Å╨▒╤Ç╤î', '╨ö╨╡╨║╨░╨▒╤Ç╤î'],
  149.      ['╨ƒ╨╛╨╜╨╡╨┤╨╡╨╗╤î╨╜╨╕╨║','╨Æ╤é╨╛╤Ç╨╜╨╕╨║','╨í╤Ç╨╡╨┤╨░','╨º╨╡╤é╨▓╨╡╤Ç╨│','╨ƒ╤Å╤é╨╜╨╕╤å╨░','╨í╤â╨▒╨▒╨╛╤é╨░', '╨Æ╨╛╤ü╨║╤Ç╨╡╤ü╨╡╨╜╤î╨╡']],
  150. 'Slovak' :
  151.     [['Janu├ír', 'Febru├ír', 'Marec', 'Apr├¡l',
  152.       'M├íj', 'J├║n', 'J├║l', 'August', 'September',
  153.       'Okt├│ber', 'November', 'December'],
  154.       ['Pondelok','Utorok','Streda','┼átvrtok','Piatok','Sobota', 'Nede─╛a']],
  155. 'Slovak-short' :
  156.     [['Janu├ír', 'Febru├ír', 'Marec', 'Apr├¡l',
  157.       'M├íj', 'J├║n', 'J├║l', 'August', 'September',
  158.       'Okt├│ber', 'November', 'December'],
  159.       ['Po','Ut','St','┼át','Pi','So', 'Ne']],
  160. 'Spanish' :
  161.     [['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo',
  162.       'Junio', 'Julio', 'Agosto', 'Septiembre',
  163.       'Octubre', 'Noviembre', 'Diciembre'],
  164.      ['Lunes', 'Martes', u'Mi\xe9rcoles', 'Jueves', 'Viernes', u'S\xe1bado', 'Domingo']],
  165. 'Swedish' :
  166.     [['Januari', 'Februari','Mars', 'April','Maj', 'Juni','Juli', 'Augusti','September', 'Oktober', 'November', 'December'],
  167.      ['M├Ñndag', 'Tisdag','Onsdag', 'Torsdag','Fredag', 'L├╢rdag','S├╢ndag']]
  168. }
  169.  
  170.  
  171. from math import sqrt
  172.  
  173. class ScCalendar:
  174.     """ Parent class for all calendar types """
  175.  
  176.     def __init__(self, year, months={}, dayOrder=[], firstDay=calendar.SUNDAY, drawSauce=True):
  177.         """ Setup base things """
  178.         # params
  179.         self.drawSauce = drawSauce # draw supplementary image?
  180.         self.year = year
  181.         self.months = months
  182.         self.dayOrder = dayOrder
  183.         self.layerImg = 'Calendar image'
  184.         self.layerCal = 'Calendar'
  185.         self.pStyle = None # paragraph style
  186.         # settings
  187.         self.firstPage = True # create only 2nd 3rd ... pages. No 1st one.
  188.         calendar.setfirstweekday(firstDay)
  189.         progressTotal(len(months))
  190.  
  191.     def setupDocVariables(self):
  192.         """ Compute base metrics here. Page layout is bordered by margins and
  193.         virtually divided by golden mean 'cut' in the bottom. The calendar is
  194.         in the bottom part - top is occupied with empty image frame. """
  195.         page = getPageSize()
  196.         self.pagex = page[0]
  197.         self.pagey = page[1]
  198.         marg = getPageMargins()
  199.         self.marginl = marg[0]
  200.         self.marginr = marg[1]
  201.         self.margint = marg[2]
  202.         self.marginb = marg[3]
  203.         self.width = self.pagex - self.marginl - self.marginr
  204.         self.height = self.pagey - self.margint - self.marginb
  205.  
  206.     def goldenMean(self, aSize):
  207.         """ Taken from samples/golden-mean.py."""
  208.         return aSize * ((sqrt(5) - 1)/2)
  209.  
  210.     def applyTextToFrame(self, aText, aFrame):
  211.         """ Insert the text with style. """
  212.         setText(aText, aFrame)
  213.         setStyle(self.pStyle, aFrame)
  214.  
  215.     def createCalendar(self):
  216.         """ Walk throudh months dict and calls monthly sheet """
  217.         if not newDocDialog():
  218.             return 'Create a new document first, please'
  219.         self.pStyle = newStyleDialog()
  220.         if  self.pStyle == None:
  221.             closeDoc()
  222.             return 'Create a default paragraph style, please'
  223.         originalUnit = getUnit()
  224.         setUnit(UNIT_POINTS)
  225.         self.setupDocVariables()
  226.         if self.drawSauce:
  227.             createLayer(self.layerImg)
  228.         createLayer(self.layerCal)
  229.         run = 0
  230.         for i in self.months:
  231.             run += 1
  232.             progressSet(run)
  233.             self.createMonthCalendar(i)
  234.         setUnit(originalUnit)
  235.         return None
  236.  
  237.     def createLayout(self):
  238.         """ Create the page and optional bells and whistless around """
  239.         self.createPage()
  240.         if self.drawSauce:
  241.             setActiveLayer(self.layerImg)
  242.             self.createImage()
  243.         setActiveLayer(self.layerCal)
  244.  
  245.     def createPage(self):
  246.         """ Wrapper to the new page with layers """
  247.         if self.firstPage:
  248.             self.firstPage = False
  249.             gotoPage(1)
  250.             return
  251.         newPage(-1)
  252.  
  253.  
  254. class ScEventCalendar(ScCalendar):
  255.     """ One day = one row calendar. I suggest LANDSCAPE orientation.\
  256.         One week per page."""
  257.  
  258.     def __init__(self, year, months = {}, dayOrder = [], firstDay = calendar.SUNDAY, drawSauce=True):
  259.         ScCalendar.__init__(self, year, months, dayOrder, firstDay, drawSauce)
  260.  
  261.     def setupDocVariables(self):
  262.         """ Compute base metrics here. Page layout is bordered by margins and
  263.         virtually divided by golden mean 'cut' in the bottom. The calendar is
  264.         in the bottom part - top is occupied with empty image frame. """
  265.         # gloden mean
  266.         ScCalendar.setupDocVariables(self)
  267.         self.gmean = self.width - self.goldenMean(self.width) + self.marginl
  268.         # calendar size = gmean
  269.         # rows and cols
  270.         self.rowSize = self.height / 8
  271.  
  272.     def createMonthCalendar(self, month):
  273.         cal = calendar.monthcalendar(self.year, month + 1)
  274.         for i in cal:
  275.             self.createLayout()
  276.             self.createHeader(self.months[month])
  277.             rowCnt = 1
  278.             for j in i: # days
  279.                 cel = createText(self.gmean + self.marginl,
  280.                                  self.margint + rowCnt * self.rowSize,
  281.                                  self.width - self.gmean, self.rowSize)
  282.                 rowCnt += 1
  283.                 if j != 0:
  284.                     self.applyTextToFrame(str(j), cel)
  285.  
  286.     def createHeader(self, monthName):
  287.         cel = createText(self.gmean + self.marginl, self.margint,
  288.                             self.width - self.gmean, self.rowSize)
  289.         self.applyTextToFrame(monthName, cel)
  290.  
  291.     def createImage(self):
  292.         """ Wrapper for everytime-the-same image frame. """
  293.         if self.drawSauce:
  294.             createImage(self.marginl, self.margint, self.gmean, self.height)
  295.  
  296. class ScClassicCalendar(ScCalendar):
  297.     """ Calendar matrix creator itself. I suggest PORTRAIT orientation.
  298.         One month per page."""
  299.  
  300.     def __init__(self, year, months = {}, dayOrder = [], firstDay = calendar.SUNDAY, drawSauce=True):
  301.         ScCalendar.__init__(self, year, months, dayOrder, firstDay, drawSauce)
  302.  
  303.     def setupDocVariables(self):
  304.         """ Compute base metrics here. Page layout is bordered by margins and
  305.         virtually divided by golden mean 'cut' in the bottom. The calendar is
  306.         in the bottom part - top is occupied with empty image frame. """
  307.         # gloden mean
  308.         ScCalendar.setupDocVariables(self)
  309.         self.gmean = self.height - self.goldenMean(self.height) + self.margint
  310.         # calendar size
  311.         self.calHeight = self.height - self.gmean + self.margint
  312.         # rows and cols
  313.         self.rowSize = self.gmean / 8
  314.         self.colSize = self.width / 7
  315.  
  316.     def createMonthCalendar(self, month):
  317.         """ Draw one month calendar per page """
  318.         cal = calendar.monthcalendar(self.year, month + 1)
  319.         self.createLayout()
  320.         self.createHeader(self.months[month])
  321.         # weeks
  322.         rowCnt = 2
  323.         for i in cal:
  324.             colCnt = 0
  325.             for j in i: # days
  326.                 cel = createText(self.marginl + colCnt * self.colSize,
  327.                                  self.calHeight + rowCnt * self.rowSize,
  328.                                  self.colSize, self.rowSize)
  329.                 colCnt += 1
  330.                 if j != 0:
  331.                     self.applyTextToFrame(str(j), cel)
  332.             rowCnt += 1
  333.  
  334.     def createHeader(self, monthName):
  335.         """ Draw calendar header. Month name and days of the week """
  336.         header = createText(self.marginl, self.calHeight, self.width, self.rowSize)
  337.         self.applyTextToFrame(monthName, header)
  338.         colCnt = 0
  339.         for i in self.dayOrder:
  340.             cel = createText(self.marginl + colCnt * self.colSize,
  341.                              self.calHeight + self.rowSize,
  342.                              self.colSize, self.rowSize)
  343.             self.applyTextToFrame(i, cel)
  344.             colCnt += 1
  345.  
  346.     def createImage(self):
  347.         """ Wrapper for everytime-the-same image frame. """
  348.         if self.drawSauce:
  349.             createImage(self.marginl, self.margint,
  350.                         self.width, self.calHeight - self.margint)
  351.  
  352.  
  353. class TkCalendar(Frame):
  354.     """ GUI interface for Scribus calendar wizard.
  355.         It's ugly and very simple. I can say I hate Tkinter :-/"""
  356.  
  357.     def __init__(self, master=None):
  358.         """ Setup the dialog """
  359.         # refernce to the localization dictionary
  360.         self.key = 'English'
  361.         Frame.__init__(self, master)
  362.         self.grid()
  363.         self.master.resizable(0, 0)
  364.         self.master.title('Scribus Calendar Wizard')
  365.         #define widgets
  366.         self.statusVar = StringVar()
  367.         self.statusLabel = Label(self, textvariable=self.statusVar)
  368.         self.statusVar.set('Select Options and Values')
  369.         # langs
  370.         # change the height = to match number of langs.
  371.         self.langLabel = Label(self, text='Select language:')
  372.  
  373.         self.langFrame = Frame(self)
  374.         self.langFrame.pack()
  375.         self.langScrollbar = Scrollbar(self.langFrame)
  376.         self.langScrollbar.pack(fill=Y, side=RIGHT)
  377.         self.langListbox = Listbox(self.langFrame, selectmode=SINGLE, height=10, yscrollcommand=self.langScrollbar.set)
  378.         self.langListbox.pack(fill=X,side=LEFT)
  379.         self.langScrollbar.config(command=self.langListbox.yview)
  380.  
  381.         keys = localization.keys()
  382.         keys.sort()
  383.         for i in keys:
  384.             self.langListbox.insert(END, i)
  385.         self.langButton = Button(self, text='Change language', command=self.languageChange)
  386.         # calendar type
  387.         self.typeLabel = Label(self, text='Calendar type')
  388.         self.typeVar = IntVar()
  389.         self.typeClRadio = Radiobutton(self, text='Classic', variable=self.typeVar, value=0)
  390.         self.typeEvRadio = Radiobutton(self, text='Event', variable=self.typeVar, value=1)
  391.         # start of week
  392.         self.weekStartsLabel = Label(self, text='Week begins with:')
  393.         self.weekVar = IntVar()
  394.         self.weekMondayRadio = Radiobutton(self, text='Mon', variable=self.weekVar, value=calendar.MONDAY)
  395.         self.weekSundayRadio = Radiobutton(self, text='Sun', variable=self.weekVar, value=calendar.SUNDAY)
  396.         # year
  397.         self.yearLabel = Label(self, text='Year:')
  398.         self.yearVar = StringVar()
  399.         self.yearEntry = Entry(self, textvariable=self.yearVar, width=4)
  400.         self.wholeYearLabel = Label(self, text='Whole year:')
  401.         self.wholeYear = IntVar()
  402.         self.wholeYearCheck = Checkbutton(self, command=self.setWholeYear, variable=self.wholeYear)
  403.         # months
  404.         self.monthLabel = Label(self, text='Months:')
  405.         self.monthListbox = Listbox(self, selectmode=MULTIPLE, height=12)
  406.         # layout stuff
  407.         self.imageLabel = Label(self, text='Draw Image Frame:')
  408.         self.imageVar = IntVar()
  409.         self.imageCheck = Checkbutton(self, variable=self.imageVar)
  410.         # closing/running
  411.         self.okButton = Button(self, text="OK", width=6, command=self.okButonn_pressed)
  412.         self.cancelButton = Button(self, text="Cancel", command=self.quit)
  413.         # setup values
  414.         self.weekMondayRadio.select()
  415.         self.typeClRadio.select()
  416.         self.yearVar.set(str(datetime.date(1, 1, 1).today().year))
  417.         self.imageCheck.select()
  418.         # make layout
  419.         self.columnconfigure(0, pad=6)
  420.         currRow = 0
  421.         self.statusLabel.grid(column=0, row=currRow, columnspan=4)
  422.         currRow += 1
  423.         self.langLabel.grid(column=0, row=currRow, sticky=W)
  424.         self.monthLabel.grid(column=3, row=currRow, sticky=W)
  425.         currRow += 1
  426.         self.langFrame.grid(column=0, row=currRow, rowspan=6, sticky=N)
  427.         self.typeLabel.grid(column=1, row=currRow, sticky=E)
  428.         self.typeClRadio.grid(column=2, row=currRow, sticky=W)
  429.         self.monthListbox.grid(column=3, row=currRow, rowspan=8)
  430.         currRow += 1
  431.         self.typeEvRadio.grid(column=2, row=currRow, sticky=W)
  432.         currRow += 1
  433.         self.weekStartsLabel.grid(column=1, row=currRow, sticky=N+E)
  434.         self.weekMondayRadio.grid(column=2, row=currRow, sticky=N+W)
  435.         currRow += 1
  436.         self.weekSundayRadio.grid(column=2, row=currRow, sticky=N+W)
  437.         currRow += 1
  438.         self.yearLabel.grid(column=1, row=currRow, sticky=N+E)
  439.         self.yearEntry.grid(column=2, row=currRow, sticky=N+W)
  440.         currRow += 1
  441.         self.wholeYearLabel.grid(column=1, row=currRow, sticky=N+E)
  442.         self.wholeYearCheck.grid(column=2, row=currRow, sticky=N+W)
  443.         currRow += 1
  444.         self.imageLabel.grid(column=1, row=currRow, sticky=N+E)
  445.         self.imageCheck.grid(column=2, row=currRow, sticky=N+W)
  446.         self.langButton.grid(column=0, row=currRow)
  447.         currRow += 3
  448.         self.rowconfigure(currRow, pad=6)
  449.         self.okButton.grid(column=1, row=currRow, sticky=E)
  450.         self.cancelButton.grid(column=2, row=currRow, sticky=W)
  451.         # fill the values
  452.         self.realLangChange()
  453.  
  454.     def languageChange(self, lang='English'):
  455.         """ Called by Change button. Get language list value and
  456.             call real re-filling. """
  457.         ix = self.langListbox.curselection()
  458.         if len(ix)==0:
  459.             self.statusVar.set('Select a language, please')
  460.             return
  461.         self.realLangChange(lang=self.langListbox.get(ix[0]))
  462.  
  463.     def realLangChange(self, lang='English'):
  464.         """ Real widget setup. Ot takes values from localization dictionary.
  465.         [0] = months, [1] Days """
  466.         self.key = lang
  467.         self.monthListbox.delete(0, END)
  468.         self.wholeYear.set(0)
  469.         for i in localization[lang][0]:
  470.             self.monthListbox.insert(END, i)
  471.  
  472.     def setWholeYear(self):
  473.         """ All/none months selection. It's called after "Whole year" check button
  474.         click. """
  475.         if self.wholeYear.get() == 1:
  476.             self.monthListbox.selection_set(0, END)
  477.         else:
  478.             self.monthListbox.selection_clear(0, END)
  479.  
  480.     def okButonn_pressed(self):
  481.         """ User variables testing and preparing """
  482.         # year
  483.         try:
  484.             year = self.yearVar.get().strip()
  485.             if len(year) != 4:
  486.                 raise ValueError
  487.             year = int(year, 10)
  488.         except ValueError:
  489.             self.statusVar.set('Year must be in the "YYYY" format e.g. 2005.')
  490.             return
  491.         # months
  492.         selMonths = self.monthListbox.curselection()
  493.         if len(selMonths) == 0:
  494.             self.statusVar.set('At least one month must be selected.')
  495.             return
  496.         months = {}
  497.         for i in selMonths:
  498.             months[int(i)] = self.monthListbox.get(i)
  499.         # day order
  500.         dayList = localization[self.key][1]
  501.         if self.weekVar.get() == calendar.SUNDAY:
  502.             dl = dayList[:6]
  503.             dl.insert(0, dayList[6])
  504.             dayList = dl
  505.         # draw images etc.
  506.         if self.imageVar.get() == 0:
  507.             draw = False
  508.         else:
  509.             draw = True
  510.         # create calendar (finally)
  511.         if self.typeVar.get() == 0:
  512.             cal = ScClassicCalendar(year, months, dayList, self.weekVar.get(), draw)
  513.         else:
  514.             cal = ScEventCalendar(year, months, dayList, self.weekVar.get(), draw)
  515.         self.master.withdraw()
  516.         err = cal.createCalendar()
  517.         if err != None:
  518.             self.master.deiconify()
  519.             self.statusVar.set(err)
  520.         else:
  521.             self.quit()
  522.  
  523.     def quit(self):
  524.         self.master.destroy()
  525.  
  526.  
  527. def main():
  528.     """ Application/Dialog loop with Scribus sauce around """
  529.     try:
  530.         statusMessage('Running script...')
  531.         progressReset()
  532.         root = Tk()
  533.         app = TkCalendar(root)
  534.         root.mainloop()
  535.     finally:
  536.         if haveDoc():
  537.             redrawAll()
  538.         statusMessage('Done.')
  539.         progressReset()
  540.  
  541. if __name__ == '__main__':
  542.     main()
  543.